import React, { Component } from 'react';
import { getBannerList, getPersonalized, getPersonalizedNewsong, getpersonalizedMv } from '../../api/discovery';
import Carousel from './carousel/carousel';
import Personalized from './Personalized';
import Newest from './newest';
import RecommendedMV from './RecommendedMV/index';
 // export default function () {
//   return <div>
//     发现音乐
//   </div>
// }

export default class index extends Component {

  constructor() {
    super();

    this.state = {
      // 轮播图
      banners: [],
      // 推荐歌单
      personalized: [],
      // 推荐音乐
      Newsong: [],
      // 推荐MV
      Mv: []
    }
  }

  // 生命周期函数调用接口函数获取数据
  componentDidMount() {
    this.getBannersData();
    // this.getPersonalizedData();
    this.getPersonalizedNewsongData();
    this.getpersonalizedMvData();
  }

  // 获取轮播图数据
  async getBannersData() {
    const { data } = await getBannerList();
    // console.log(data);
    // if(data.code !== 200) return 
    this.setState({
      banners: data.banners
    })
    // console.log('轮播图')
  }

  // 获取推荐歌单数据
  async getPersonalizedData() {
    const { data } = await getPersonalized();
    this.setState({
      personalized: data.result
    })
  }

  // 获取推荐音乐的数据
  async getPersonalizedNewsongData() {
    const { data } = await getPersonalizedNewsong();
    this.setState({
      personalized: data.result
    })
    // console.log('推荐音乐');
  }

  // 获取推荐MV的数据
  async getpersonalizedMvData() {
    const { data } = await getpersonalizedMv();
    // console.log(data);
    this.setState({
      personalized: data.result
    })
    // console.log('推荐MV');
  }

  // ascasc = () => {
  //   this.props.lickc()
  // }

  render() {
    return (
      <div>
        <Carousel banners={this.state.banners} />
        <Personalized personalized={this.state.personalized} />
        <Newest newest={this.state.Newsong} lickchnd={(id)=>{this.props.lickc(id)}}/>
        <RecommendedMV />
      </div>
    )
  }
}